﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Confucius.entity;
using System.IO.IsolatedStorage;
using Confucius.utils;
using Confucius.daoImpl;

namespace Confucius.pages
{
    public partial class CheckedQuestPage : PhoneApplicationPage
    {
        private Quest currentQuest;

        public CheckedQuestPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(CheckedQuestPage_Loaded);
        }

        private void CheckedQuestPage_Loaded(object sender, RoutedEventArgs e)
        {
            String questID = "";
            String gameID = "";
            if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_QUESTID))
            {
                questID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_QUESTID];
            }
            if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
            {
                gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
            }
            if (questID == "")
            {
                MessageBox.Show("You haven't checked in any quest, please try to find one.");
                NavigationService.GoBack();
            }
            if (gameID == "")
            {
                MessageBox.Show("Cannot find matched quests, please contact team Confucius.");
                NavigationService.GoBack();
            }

            currentQuest = new QuestDAOImpl().readQuest(questID, gameID);
            QuestTitle.Text = currentQuest.Title;
            QuestStarter.Text = currentQuest.StartText;
        }
    }
}